package com.kfm.shop.controller;

import com.alibaba.fastjson.JSON;
import com.kfm.shop.domain.Product;
import com.kfm.shop.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/product")
public class ProductController {

    @Resource
    private ProductService productService;

    @RequestMapping("/demo1")
    public String demo1() {
        return "demo1";
    }

    @RequestMapping("/demo2")
    public String demo2() {
        return "demo2";
    }

    @GetMapping("/find/{id}")
    public Product findByPid(@PathVariable("id") Integer pid) {
        log.info("接下来要进行{}号商品信息的查询", pid);
        Product pro = productService.findByPid(pid);
        log.info("商品信息查询成功,内容为{}", JSON.toJSONString(pro));
        return pro;
    }
}
